package com.crawler.demo.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.crawler.demo.vo.SimpleVo;
import com.crawler.waf.security.authens.UserToken;
import com.crawler.waf.support.Constants;
import com.crawler.waf.utils.TokenManager;
import com.crawler.waf.utils.UcManager;

/**
 * 授权
 * @author rubekid
 * @date 2016年9月24日
 */
@RestController
@RequestMapping(value="/oauth")
public class OauthController {
	
	/**
	 * 授权
	 * @return
	 */
	@RequestMapping(value = "/authorize", method = RequestMethod.POST)
	public UserToken authorize(){
		//TODO 登录获取用户信息
		Long userId = 18030285080L;
		return TokenManager.generate(userId, Constants.AUTHORIZATION_TYPE_MAC);
	}
	
	/**
	 * 获取用户信息
	 * @return
	 */
	@RequestMapping(value = "/user", method = RequestMethod.GET)
	public SimpleVo get(){
		Long userId = UcManager.getUserId();
		//TODO 根据用户userId 获取缓存中的用户信息
		return new SimpleVo(userId);
	}


}
